<?php

use app\models\Api;
use app\models\Isp;
use app\models\Package;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\widgets\Pjax;

/**
 * @var $this yii\web\View
 * @var $model app\models\CardSetPackageForm
 */

$this->title = '批量设置套餐';
$this->params['breadcrumbs'][] = '物联网卡管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $form = ActiveForm::begin();?>
<fieldset>
    <legend><label><input type="radio" name="CardSetPackageForm[source]" value="range" checked="checked"> 设定起止卡号</label></legend>
    <?php echo $form->field($model, 'iccid_start')->hint('开始号码和结束号码必须同时填写。');?>
    <?php echo $form->field($model, 'iccid_end')->hint('开始号码结束号码和ICCID列表必须至少填写一项。');?>
</fieldset>
<?php echo $form->field($model, 'iccid_list')->textarea(['style' => 'min-height:200px;'])->label('<label><input type="radio" name="CardSetPackageForm[source]" value="iccid"> 直接填写ICCID列表</label>');?>
<fieldset>
    <legend><label><input type="radio" name="CardSetPackageForm[source]" value="search"> 通过查询条件搜索</label></legend>
    <?php echo $form->field($model, 'search_api_id')->dropDownList(ArrayHelper::map(Api::find()->all(), 'id', 'name'), ['prompt' => '搜索接口']);?>
    <?php Pjax::begin(['id' => 'pjax_isp']);?>
    <?php echo $form->field($model, 'search_isp_id')->dropDownList(ArrayHelper::map(Isp::find()->andWhere(['status' => Isp::STATUS_OK])->andWhere(['api_id' => Yii::$app->request->get('search_api_id')])->all(), 'id', 'name'), ['prompt' => '搜索运营商']);?>
    <?php Pjax::end();?>
    <?php echo $form->field($model, 'search_batch_no');?>
    <?php echo $form->field($model, 'package_id')->dropDownList(ArrayHelper::map(Package::find()->all(), 'id', 'name'), ['prompt' => '选择套餐']);?>
</fieldset>
<div class="form-group">
    <div class="col-lg-offset-1 col-lg-11">
        <button type="button" class="btn btn-default" onclick="window.history.go(-1);"><i class="ace-icon fa fa-arrow-left bigger-110"></i>返回</button>
        <button class="btn btn-primary"><i class="ace-icon fa fa-check bigger-110"></i>保存</button>
        <button type="reset" class="btn btn-warning"><i class="ace-icon fa fa-undo bigger-110"></i>重置</button>
    </div>
</div>
<?php $form->end();?>
<script>
    function pageInit() {
        $('[name="CardSetPackageForm[search_api_id]"]').change(function () {
            var id = $(this).val();
            $.pjax.reload('#pjax_isp', {
                history: false,
                push: false,
                url: '<?php echo Url::current(['ajax' => 1]);?>&search_api_id=' + id
            });
        });
    }
</script>
